import {
    rangkingStore,
    playerStore
} from '../../store/index'
import { getSongDetail } from '../../service/api_music'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        ranking: '',
        type:'',
        songInfo: {}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        const type = options.type
        this.setData({type})
        if (type === 'menu') {
            const id = options.id
            getSongDetail(id).then(res=>{
                this.setData({
                    songInfo:res.playlist
                })
            })
        } else if (type === 'rank') {
            const ranking = options.ranking
            this.setData({ ranking })
            rangkingStore.onState(ranking, res => {
                this.setData({
                    songInfo: res
                })
            })
        }
    },
    handleSongItemClick(event){
        const index = event.currentTarget.dataset.index
        playerStore.setState('playListSongs',this.data.songInfo.tracks)
        playerStore.setState('playListIndex',index)
    }
})